<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue列表渲染</title>
    <style>
        .tb {
            width: 500px;
            border-collapse: collapse;
            border: 1px solid grey;
        }

        .tb td,
        .tb th {
            text-align: center;
            border-bottom: 1px solid grey;
        }

        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <table class="tb">
            <tr>
                <th>序号</th>
                <th>编号</th>
                <th>昵称</th>
                <th>类型</th>
                <th>操作</th>
            </tr>
            <tr v-for="(item,i) in petList">
                <td>{{i+1}}</td>
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.type}}</td>
                <td><button @click="del(item.id)">删除</button></td>
            </tr>
        </table>
    </div>
    <script src="js/vue.js"></script>
    <script>
        new Vue({
            el: "#app",
            data: {
                petList: [{
                    id: 1001,
                    name: "小黑",
                    type: "狗"
                }, {
                    id: 1002,
                    name: "小红",
                    type: "猫"
                }, {
                    id: 1003,
                    name: "小绿",
                    type: "狗"
                }]
            },
            methods: {
                del(id) {
                    this.petList = this.petList.filter(item => item.id !== id)
                }
            },
        })
    </script>
</body>

</html>